home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 14 / 014.d81 / comal tutor #2 (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  13KB  |  332 lines

  1. 1 goto 8
  2. 5 ifpeek(49152)<>120orpeek(51200)<>76orpeek(52016)<>32then7
  3. 6 ifpeek(52080)=173andpeek(52176)=169then8
  4. 7 load"routines",8,1
  5. 8 pokev+33,1:q$=chr$(34):vt$="":dimvt$(25)
  6. 9 fori=.to25:vt$(i)=left$(vt$,i+1):next:vt$=""
  7. 10 r=53265:c=128:v=53248:s=v+1024:li=52016:wi=51200:cl=51203:su=51206:sd=51209
  8. 12 pokes+23,.:pokes+4,128
  9. 15 gosub1000:print"   [215]elcome to the second installment"
  10. 16 print"of [204]oadstar's [195][207][205][193][204][160]0.14 [212]utorial.  [201]n
  11. 17 [153]"the first installment, you entered and
  12. 18 print"ran a short [195][207][205][193][204][160]program to convert
  13. 19 [153]"degrees ascarenheit into degrees lenelsius
  14. 20 print"without understanding how the program
  15. 21 [153]"worked.  atnt the time, we were concen-
  16. 22 print"trating more on program entry.
  17. 23 [153]"   (NULL)ow that we have the program in the
  18. 24 print"64's memory, let's see how it works.
  19. 25 s%[178][171]1:[141]1200
  20. 26 [153]"   (NULL)e will assume that the computer is
  21. 27 print"just as we left it.  [204][201][211][212][160]the program
  22. 28 [153]"to be sure it is still there:
  23. 30 gosub1160:gosub1300:x%=.:y%=16:a$="[204][201][211][212]":gosub1600
  24. 31 ifethena$=mid$(a$,e):e=.:gosub1605:goto31
  25. 32 x%=4:y%=16:gosub1500:ifk$<>chr$(13)then32
  26. 33 print:print"0010 [201][206][208][213][212] "q$"[196][197][199][210][197][197][211] [198]? "q$": [198][193][210][197][206][200][197][201][212]
  27. 34 [153]"0020 lenval(NULL)(NULL)right$(NULL)(NULL):=(ascatn(NULL)val(NULL)left$valright$(NULL)-32)*(5/9)
  28. 35 print"0030 [208][210][201][206][212] [198][193][210][197][206][200][197][201][212];"q$"[198] ="q$";[195][197][204][211][201][213][211];"q$"[195]"q$"
  29. 36 [141]1150:[153]"stop   (NULL)ep, still there!  mid$ust for prac-
  30. 37 print"tice, [210][213][206][160]the program and find out how
  31. 38 [153]"many degrees lenelsius -40 degrees "
  32. 39 [153]"ascarenheit converts into:
  33. 40 gosub1160:x%=.:y%=21:a$="[210][213][206]":gosub1600
  34. 41 ifethena$=mid$(a$,e):e=.:gosub1605:goto41
  35. 42 x%=3:y%=21:gosub1500:ifk$<>chr$(13)then42
  36. 43 print:print"[196][197][199][210][197][197][211] [198]? ";:
  37. 45 x%=11:y%=22:a$="-40":gosub1600
  38. 46 ifethena$=mid$(a$,e):e=.:gosub1605:goto46
  39. 47 x%=14:y%=22
  40. 48 gosub1500:ifk$<>chr$(13)then48
  41. 49 print:print"-40 [198] = -40 [195]":gosub1700
  42. 50 gosub1035:gosub1150:print"[144][146]   [211]o -40 degrees is the 'meeting
  43. 51 [153]"place' for the two temperature scales!":[141]1205
  44. 55 [153]"   (NULL)et's try one more.  (NULL)ince 72 "
  45. 56 [153]"degrees ascarenheit is considered the "
  46. 57 [153]"most comfortable temperature for us
  47. 58 print"human beings, let's try to find the
  48. 59 [153]"lenelsius equivilant of 72 degrees asc:
  49. 60 gosub1160:gosub1300:x%=.:y%=24:a$="[210][213][206]":gosub1600
  50. 61 ifethena$=mid$(a$,e):e=.:gosub1605:goto61
  51. 62 x%=3:y%=24
  52. 63 gosub1500:ifk$<>chr$(13)then63
  53. 64 gosub1700:print"[196][197][199][210][197][197][211] [198]? ";
  54. 65 x%=11:y%=24:a$="72":gosub1600
  55. 66 ifethena$=mid$(a$,e):e=.:gosub1605:goto66
  56. 67 x%=13:y%=24
  57. 68 gosub1500:ifk$<>chr$(13)then244
  58. 69 gosub1700:print" 72 [198] = 22.2222222 [195]";:gosub1700:gosub1700:print"[145]"
  59. 70 gosub1035:gosub1150:print"[144][146]   [211]o when it's around 22 [195]elsius"
  60. 71 print"outdoors, it's quite comfortable.
  61. 72 [153]"   left$ow does this program work?  right$n "
  62. 73 [153]"order to answer that, we must be able"
  63. 74 [153]"to see our program.
  64. 75 gosub1205
  65. 76 print"   [201]n order to do [212][200][193][212], we must [204][201][211][212]
  66. 77 [153]"the program again.  (peeket you'd (NULL)val(NULL)val(NULL)
  67. 78 print"have guessed!)  [193]nyway, go ahead and
  68. 79 [153]"(NULL)right$(NULL)(NULL)closethe program again:
  69. 80 gosub1160:gosub1300:x%=.:y%=24:a$="[204][201][211][212]":gosub1600
  70. 81 ifethena$=mid$(a$,e):e=.:gosub1605:goto81
  71. 82 x%=4:y%=24:gosub1500:ifk$<>chr$(13)then82
  72. 83 gosub1700:print"0010 [201][206][208][213][212] "q$"[196][197][199][210][197][197][211] [198]? "q$": [198][193][210][197][206][200][197][201][212]";
  73. 84 gosub1700:print"0020 [195][197][204][211][201][213][211]:=([198][193][210][197][206][200][197][201][212]-32)*(5/9)";:gosub1700
  74. 85 print"0030 [208][210][201][206][212] [198][193][210][197][206][200][197][201][212];"q$"[198] ="q$";[195][197][204][211][201][213][211];"q$"[195]"q$;:gosub1700:gosub1700
  75. 86 gosub1035:gosub1150:print"[144]   [212]he first line, line 10 (ignore the
  76. 87 [153]"leading zeroes for now), is an right$(NULL)(NULL)(NULL)(NULL)
  77. 88 print"statement.  [193]n [201][206][208][213][212][160]statement's "
  78. 89 print"purpose is to [201][206][208][213][212] values into the "
  79. 90 print"program from the outside world, "
  80. 91 print"usually from the user via the":print"keyboard.":gosub1205
  81. 92 print"[201]t must [193][204][215][193][217][211] have a 'variable' that"
  82. 93 print"is simply a name given to the "
  83. 94 print"[201][206][208][213][212]ted data (in this case, the "
  84. 95 print"variable is named '[198][193][210][197][206][200][197][201][212]').  [193] "
  85. 96 print"variable name may consist of any "
  86. 97 print"number of letters or digits, so long"
  87. 98 print"as the first character is a letter.":print"[193]postrophes";
  88. 99 print" and left-arrow characters":print"are legal as well."
  89. 100 print"[212]he variable named in the [201][206][208][213][212]"
  90. 101 print"statement receives as its value the"
  91. 102 print"value 'keyed-in' by the user.":gosub1200
  92. 105 print"   [212]his simply means that the [201][206][208][213][212]
  93. 106 [153]"statement displays the message between
  94. 107 print"the double-quote symbols, suspends the
  95. 108 [153]"execution of the program, and waits
  96. 109 print"for the user to type in something and
  97. 110 [153]"hit the (NULL)val(NULL)(NULL)(NULL)(NULL) key.  right$f that something
  98. 111 print"is a legal number, the variable (in
  99. 112 [153]"this case, ascatn(NULL)val(NULL)left$valright$(NULL)) receives as its
  100. 113 print"value the number.  [212]his means that,
  101. 114 [153]"from now on, whenever len(NULL)(NULL)atn(NULL)closeencounters
  102. 115 print"the word [198][193][210][197][206][200][197][201][212][160]within the program,
  103. 116 [153]"it will substitute the value typed in!":[141]1200
  104. 120 [153]"   (NULL)he 'prompt string' is optional in
  105. 121 print"an [201][206][208][213][212][160]statement.  [201]f no prompt is
  106. 122 [153]"specified, len(NULL)(NULL)atn(NULL)closedisplays a simple '?'
  107. 123 print"(question mark) to let the user know
  108. 124 [153]"that a response is requested from him.
  109. 125 print"   [204]ine 20 (0020) is an example of an
  110. 126 [153]"'assignment' statement.  atnn assignment
  111. 127 print"statement is used to assign a value to"
  112. 128 print"a variable.  [193]n assignment statement"
  113. 129 print"gets its value for the variable from"
  114. 130 print"an expression."                 :gosub1200
  115. 131 :
  116. 132 :
  117. 133 print"   [193]n 'expression' can be a [195][207][206][211][212][193][206][212],"
  118. 134 print"(such as 5 or 18.9), another variable,"
  119. 135 print"or a combination of constants and/or"
  120. 136 print"variables separated by [207][208][197][210][193][212][207][210][211]."
  121. 137 print"[207]perators represent mathematical"
  122. 139 print"operations such as '+' for addition,"
  123. 140 print"'-' for subtraction, '*' for"
  124. 141 print"multiplication, or '/' for division.)":gosub1200
  125. 145 print"   [204]et's take a closer look at line
  126. 146 [153]"0020.  'lenval(NULL)(NULL)right$(NULL)(NULL)' is a variable, like
  127. 147 print"'[198][193][210][197][206][200][197][201][212]'.  [201]t is the 'destination'
  128. 148 [153]"variable, the variable which will"
  129. 149 [153]"receive the value.  (NULL)he two symbols"
  130. 150 [153]"after it (':=') form the 'assignment"
  131. 151 [153]"operator', which indeed is what tells"
  132. 152 [153]"us (and len(NULL)(NULL)atn(NULL)) that this is an"
  133. 153 [153]"assignment statement!
  134. 154 print"  [212]he remainder of the line is the"
  135. 155 print"actual expression.":gosub1200
  136. 156 print"   [212]he expression, in this case, is"
  137. 157 print"'([198][193][210][197][206][200][197][201][212]-32)*(5/9)'. [212]he parenthe-
  138. 158 [153]"ses are used to determine what to"
  139. 159 [153]"calculate first. right$n this case, '(5/9)'
  140. 160 print"is computed first, and the result of
  141. 161 [153]"'.555555556' is held in memory.  (NULL)hen,
  142. 162 print"32 is subtracted